package com.google.code.jmarias.server.tcp;

import com.google.code.jmarias.common.RegisteredUser;
import com.google.code.jmarias.common.action.SignedAction;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.BlockingQueue;

/**
 * Predstavuje prostredi s nekolika mistnostmi, ve kterych se hraji karetni hry.
 *
 * @author Ondrej Michal
 */
public class Casino {

    // @TODO tohle je tu jen kvuli tomu, aby mohli lokalne komunikovat boti, neda se lokalni komunikace udelat jinak?
    private BlockingQueue<SignedAction> clientToServerActions;

    private Map<String, RegisteredUser> registeredPlayers = new HashMap<String, RegisteredUser>();

    /** Seznam aktivnich mistnosti v casinu. */
    private Map<Long, Room> rooms = new HashMap<Long, Room>();
    private Long roomIndex = 0L;

    public Casino(BlockingQueue<SignedAction> clientToServerActions) {
        this.clientToServerActions = clientToServerActions;
        registeredPlayers.put("xandre", new RegisteredUser("xandre", "12345"));
        registeredPlayers.put("pepa", new RegisteredUser("pepa", "11111"));
        registeredPlayers.put("martin", new RegisteredUser("martin", "55555"));
    }

    public Room createRoom(AbstractGameFactory factory, AbstractContactableUser client) {
        roomIndex++;
        Room result = new Room(clientToServerActions, roomIndex, factory, client);
        rooms.put(roomIndex, result);
        return result;
    }

    public Map<Long, Room> getRooms() {
        return Collections.unmodifiableMap(rooms);
    }

    public Map<String, RegisteredUser> getRegisteredPlayers() {
        return Collections.unmodifiableMap(registeredPlayers);
    }

}
